package com.snap.vseries.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import io.protostuff.Tag;

/**
 * 这版 只实现恒温段和循环段
 * 恒温段和循环段的区别只是循环数的不同，循环段的循环次数>1  而恒温段的循环次数为1
 */
public class ProgramStage implements Serializable, Cloneable {
    @Tag(1)
    private int cycleCount = 1;
    @Tag(2)
    private List<ProgramSection> sections;
    private transient boolean isChecked;//是否选中

    public ProgramStage() {
    }

    public int getCycleCount() {
        return cycleCount;
    }

    public void setCycleCount(int cycleCount) {
        this.cycleCount = cycleCount;
    }

    public boolean isChecked() {
        return isChecked;
    }

    public void setChecked(boolean checked) {
        isChecked = checked;
    }

    public List<ProgramSection> getSections() {
        return sections;
    }

    public void setSections(List<ProgramSection> sections) {
        this.sections = sections;
    }

    public void addSection(ProgramSection section) {
        if (sections == null) {
            sections = new ArrayList<>();
        }
        sections.add(section);
    }

    public void addSection(ProgramSection section, int index) {
        if (sections == null) {
            sections = new ArrayList<>();
        }
        sections.add(index, section);
    }

    public boolean deleteSection(int index) {
        if (index >= sections.size()) {
            return false;
        }
        sections.remove(index);
        return true;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        Object obj = super.clone();
        List<ProgramSection> sections = ((ProgramStage) obj).getSections();
        List<ProgramSection> sectionsClone = new ArrayList<>();
        for (int i = 0; i < sections.size(); i++) {
            ProgramSection section = (ProgramSection) sections.get(i).clone();
            sectionsClone.add(section);
        }
        ((ProgramStage) obj).setSections(sectionsClone);
        return obj;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        ProgramStage info = (ProgramStage) o;
        if (cycleCount != info.cycleCount) {
            return false;
        }
        if (sections == null) {
            return info.sections == null;
        } else {
            if (!sections.equals(info.sections)) {
                return false;
            }
            return true;
        }
    }
}
